/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package battleship.player;

import battleship.board.BoardSide;
import battleship.board.AbstractBoardSide;

/**
 *
 * @author ali
 */
public abstract class AbstractPlayer implements PlayerType{

    protected String name = "dumy name";
    protected AbstractBoardSide board = new BoardSide();


    public AbstractBoardSide getBoard(){
        return board;
    }

    public AbstractPlayer(String n) {
        name = n;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object obj) {
        if(obj instanceof PlayerType){
            String nm = ((PlayerType)obj).getName();
            if(nm.equals(name)){
                return true;
            }
        }
        return false;
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }

    @Override
    public String toString() {
        return super.toString();
    }

    public void handleHit(int x, int y){
        boolean isAlreadyHit = board.isHit(x, y);
        if(!isAlreadyHit){
            board.hit(x, y);
        }
    }

}
